package leetcode.code;

import leetcode.helper.tree.TreeNode;

public class Solution230 {
	int ans;
	int count;

	public int kthSmallest(TreeNode root, int k) {
		ans = 0;
		count = 0;
		f(root, k);
		return ans;
	}

	private void f(TreeNode root, int k) {
		if (root == null)
			return;
		f(root.left, k);
		count++;
		if (count == k) {
			ans = root.val;
			return;
		}
		f(root.right, k);
	}
}
